package com.ryskoo.catering.productattr.repository;

import com.ryskoo.catering.productattr.domain.ProductAttrPO;
import com.ryskoo.framework.core.repository.BasicJPAImpl;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ProductAttrJPAImpl extends BasicJPAImpl<ProductAttrPO> implements IProductAttrRepository{

    @Override
    public List<String> getUuidsByMainUuid(String mainUUid) {
        String hql = "select o.uuid from ProductAttrPO o where o.productUuid = :productUuid";
        Query query = getH4Session().createQuery(hql);
        query.setString("productUuid",mainUUid);
        return query.list();
    }

    @Override
    public List<ProductAttrPO> getAttrsByMainUuid(String mainUuid) {
        String hql = "from ProductAttrPO o where o.productUuid = :productUuid order by o.position asc ";
        Query query = getH4Session().createQuery(hql);
        query.setString("productUuid",mainUuid);
        return query.list();
    }

    @Override
    public List<String> getUuidsByMainUuids(List<String> mainUuids) {
        String hql = "select o.uuid from ProductAttrPO o where o.productUuid in (:mainUuids)";
        Query query = getH4Session().createQuery(hql);
        query.setParameterList("mainUuids",mainUuids);
        return query.list();
    }
}
